<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Layui树形表格2.x演示</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="demo.css">
    <style>
        thead td .layui-icon {
            vertical-align: middle;
        }
    </style>
</head>
<body class="page-no-scroll">

<div class="page-wrapper">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>Layui树形表格2.x演示</legend>
    </fieldset>
    <div class="layui-btn-container">
        <a href="index.html" class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe65c;</i>返回
        </a>
        <button class="layui-btn layui-btn-sm layui-btn-primary">支持格式校验</button>
        <a class="layui-btn layui-btn-sm layui-btn-primary" href="editAdv.html" style="position: relative;">
            <i class="layui-icon">&#xe642;</i>复杂编辑&nbsp;&nbsp;
            <span class="layui-badge-dot" style="position: absolute;right: 3px;top: 3px;"></span>
        </a>
    </div>

    <table id="demoTreeTable1"></table>
</div>

<!--<div class="right-desc">
    <div class="layui-text desc-item">
        treeTable时隔一年进行了彻底重构，不再基于数据表格table，从零开始，
        实现了数据表格的大部分功能，在使用方法上与数据表格一致，
        并且支持懒加载、复选框联动、折叠状态记忆等功能，
        <a href="https://gitee.com/whvse/treetable-lay" target="_blank">码云下载</a>。
    </div>
    <div class="layui-text desc-item" style="padding: 0;overflow: hidden;">
        <img src="https://s2.ax1x.com/2019/08/23/msiO78.png" width="100%"/>
        <div style="padding: 5px 10px;">
            EasyWeb管理系统模板
            <a href="https://demo.easyweb.vip/iframe/" style="float: right;" target="_blank">前往查看</a>
        </div>
    </div>
</div>-->

<!-- 表格操作列 -->
<script type="text/html" id="demoTreeTableBar1">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表格状态列 -->
<script type="text/html" id="demoTreeTableState1">
    <input type="checkbox" lay-filter="ckState" value="{{d.id}}" lay-skin="switch"
           lay-text="正常|锁定" {{d.state==0?'checked':''}}/>
</script>

<div class="page-loading">
    <div class="ball-loader sm">
        <span></span><span></span><span></span><span></span>
    </div>
</div>

<script src="../layui/layui.js"></script>
<script>
    layui.config({
        base: '../'
    }).extend({
        treeTable: 'treeTable/treeTable'
    }).use(['layer', 'util', 'treeTable'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var util = layui.util;
        var treeTable = layui.treeTable;

        // 渲染表格
        var insTb = treeTable.render({
            elem: '#demoTreeTable1',
            tree: {
                iconIndex: 1
            },
            cols: [
                {type: 'numbers'},
                {field: 'id', title: 'ID'},
                {field: 'name', title: 'name<i class="layui-icon">&#xe642;</i>', width: 160, edit: 'text'},
                {field: 'createTime', title: '创建时间<i class="layui-icon">&#xe642;</i>', width: 180, edit: 'text'},
                {templet: '#demoTreeTableState1', title: '状态', width: 100},
                {align: 'center', toolbar: '#demoTreeTableBar1', title: '操作', width: 120}
            ],
            reqData: function (data, callback) {
                var url = '../../json/list';
                url += ((data ? ('_' + data.id) : '') + '.json');
                $.get(url, function (res) {
                    callback(res.data);
                });
            },
            style: 'margin-top:0;'
        });

        treeTable.on('edit(demoTreeTable1)', function (obj) {
            console.log(obj);
            if (true) {
                layer.tips('格式不正确', $(this), {tips: [1, '#FF5722']});
                return false;
            }
        });

        setTimeout(function () {
            $('body').children('.page-loading').hide();
            $('body').removeClass('page-no-scroll');
        }, 100);

    });
</script>
</body>
</html>